package com.zplus.managers.petservices.utils;

import com.zplus.managers.petservices.entities.EntityBase;

import java.util.List;
import java.util.Map;


public class Page
{
    private Map<String, ? extends EntityBase> pageContent;
    private List<? extends EntityBase> pageContentList;
    private int totalPage;
    private int curPage;
    private int totalitem;
    private PageState pstate;


    public void setState(PageState state)
    {
        this.pstate = state;
    }
    /**
     * return the state code:
     * 0 : ORIGIN
     * 1 : OUTOFINDEX
     * 2 : NORMAL
     */
    public int getPageState()
    {
        int info = 0;
        switch(pstate)
        {
            case OUTOFINDEX:
                info = 1;
                break;
            case NORMAL:
                info = 2;
                break;
            case ORIGIN:
                info = 0;
                break;
        }
        return info;
    }


    /**
     * return the state info, not state code
     * @return state info
     */
    public PageState getPageStateInfo()
    {
        return pstate;
    }
    public Page()
    {
        setState(PageState.ORIGIN);
    }
    public Page(Map<String, ? extends EntityBase> pageContent, int totoalPage, int curPage, PageState p)
    {
        this.pageContent = pageContent;
        this.totalPage = totoalPage;
        this.curPage = curPage;
        this.pstate = p;
        this.totalitem = pageContent.size();
    }

    public Page(List<? extends EntityBase> pageContent, int totoalPage, int curPage, PageState p)
    {
        this.pageContentList = pageContent;
        this.totalPage = totoalPage;
        this.curPage = curPage;
        this.pstate = p;
        this.totalitem = pageContent.size();
    }

    public void load(Map<String, ? extends EntityBase>pageContent, int totalPage, int curPage)
    {
        this.pageContent = pageContent;
        this.totalPage = totalPage;
        this.curPage = curPage;
        setState(PageState.NORMAL);
        this.totalitem = pageContent.size();
    }

    public void load(List<?extends EntityBase> pageContentList, int totalPage, int curPage,int totalitems)
    {
        this.pageContentList = pageContentList;
        this.totalPage = totalPage;
        this.curPage = curPage;
        setState(PageState.NORMAL);
        this.totalitem = totalitems;
    }


    public Map<String, ? extends EntityBase> getPageContent()
    {
        return pageContent;
    }

    public List<? extends EntityBase> getPageContentList()
    {
        return pageContentList;
    }

    public int getTotalPage()
    {
        return totalPage;
    }

    public int getCurPage()
    {
        return curPage;
    }

    public PageState getPstate()
    {
        return pstate;
    }

    public int getTotalitem()
    {
        return totalitem;
    }
}
